package com.aspose.cells;

import java.security.MessageDigest;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

class zbv {
   private MessageDigest a;
   private Cipher b;
   private int c;
   private byte[] d;
   private byte[] e;
   private byte[] f;
   private byte[] g;

   public zbv(String var1, byte[] var2, byte[] var3, byte[] var4, String var5, long var6, long var8, long var10, long var12) throws Exception {
      this(var1, var2, (int)var12);
      this.f = var3;
      this.g = var4;
   }

   public zbv(String var1, byte[] var2, int var3) throws Exception {
      this.a(var1, var2, this.b(var3), 2);
   }

   public zbv(String var1, int var2) throws Exception {
      this.a(var1, new byte[]{83, 15, -37, -89, 86, -75, -10, -115, 61, -31, -106, 31, 16, 81, 36, 2}, var2, 1);
   }

   private void a(String var1, byte[] var2, int var3, int var4) throws Exception {
      if (var1 != null && var1.length() >= 1) {
         this.d = var1.getBytes("UTF-16LE");
         if (this.d.length < 1) {
            throw new IllegalArgumentException("The password could not be null or empty.");
         } else {
            this.c = var3;
            this.e = var2;
            this.a = MessageDigest.getInstance("SHA-1");
            this.b = Cipher.getInstance("AES/ECB/NoPadding");
            SecretKeySpec var5 = new SecretKeySpec(this.c(), "AES");
            this.b.init(var4, var5);
         }
      } else {
         throw new IllegalArgumentException("The password could not be null or empty.");
      }
   }

   private byte[] b(byte[] var1, byte[] var2) {
      byte[] var3 = new byte[var1.length + var2.length];
      System.arraycopy(var2, 0, var3, 0, var2.length);
      System.arraycopy(var1, 0, var3, var2.length, var1.length);
      byte[] var4 = this.a(var3);
      var3 = new byte[24];
      byte[] var5 = new byte[4];

      for(int var6 = 0; var6 < 50000; ++var6) {
         zaks.a(var5, 0, (int)var6);
         System.arraycopy(var5, 0, var3, 0, 4);
         System.arraycopy(var4, 0, var3, 4, 20);
         var4 = this.a(var3);
      }

      return var4;
   }

   private byte[] c() {
      byte[] var1 = this.b(this.d, this.e);
      byte[] var2 = new byte[24];
      System.arraycopy(var1, 0, var2, 0, var1.length);
      Object var6 = null;
      var2 = this.a(var2);
      byte[] var3 = new byte[64];
      Arrays.fill(var3, (byte)54);

      for(int var4 = 0; var4 < 20; ++var4) {
         var3[var4] ^= var2[var4];
      }

      byte[] var7 = new byte[64];
      Arrays.fill(var7, (byte)92);

      for(int var5 = 0; var5 < 20; ++var5) {
         var7[var5] ^= var2[var5];
      }

      byte[] var8;
      switch(this.c) {
      case 128:
         var8 = new byte[16];
         System.arraycopy(this.a(var3), 0, var8, 0, 16);
         return var8;
      case 192:
         var8 = new byte[24];
         System.arraycopy(this.a(var3), 0, var8, 0, 16);
         System.arraycopy(this.a(var7), 0, var8, 16, 8);
         return var8;
      case 256:
         var8 = new byte[32];
         System.arraycopy(this.a(var3), 0, var8, 0, 16);
         System.arraycopy(this.a(var7), 0, var8, 16, 16);
         return var8;
      default:
         throw new IllegalArgumentException("Unsupported key size: " + this.c);
      }
   }

   public boolean a() {
      return this.a(this.f, this.g);
   }

   public boolean a(byte[] var1, byte[] var2) {
      try {
         byte[] var3 = this.b.doFinal(var1);
         var3 = this.a(var3);
         var2 = this.b.doFinal(var2);

         for(int var4 = 0; var4 < 20; ++var4) {
            if (var3[var4] != var2[var4]) {
               return false;
            }
         }

         return true;
      } catch (Exception var5) {
         throw new RuntimeException(var5);
      }
   }

   public com.aspose.cells.b.a.d.zh a(com.aspose.cells.b.a.d.zh var1) throws Exception {
      com.aspose.cells.b.a.d.za var2 = new com.aspose.cells.b.a.d.za(var1);
      int var3 = (int)((var1.h() + 15L) / 16L);
      com.aspose.cells.b.a.d.zh var4 = new com.aspose.cells.b.a.d.zh(var3 * 16);
      com.aspose.cells.b.a.d.zb var5 = new com.aspose.cells.b.a.d.zb(var4);
      var2.k().a(8L, 0);
      byte[] var6 = new byte[16];

      int var7;
      for(var7 = 0; var7 < var3 - 1; ++var7) {
         var2.a(var6, 0, 16);
         this.b.doFinal(var6, 0, 16, var6);
         var5.a(var6);
      }

      var7 = var2.a(var6, 0, 16);
      if (var7 > 0) {
         if (var7 < 16) {
            Arrays.fill(var6, var7, 16, (byte)0);
         }

         this.b.doFinal(var6, 0, 16, var6);
         var5.a(var6);
      }

      var2.l();
      var4.a(0L, 0);
      return var4;
   }

   public com.aspose.cells.b.a.d.zh b() throws Exception {
      com.aspose.cells.b.a.d.zh var1 = new com.aspose.cells.b.a.d.zh(248);
      com.aspose.cells.b.a.d.zb var2 = new com.aspose.cells.b.a.d.zb(var1);
      byte[] var3 = new byte[16];
      var3[0] = 3;
      var3[2] = 2;
      var3[4] = 36;
      var3[8] = -92;
      var3[12] = 36;
      var2.a(var3);
      Arrays.fill(var3, (byte)0);
      zaks.a(var3, 4, (short)this.a(this.c));
      var3[8] = 4;
      var3[9] = -128;
      var3[12] = (byte)this.c;
      var2.a(var3);
      Arrays.fill(var3, (byte)0);
      var3[0] = 24;
      var2.a(var3, 0, 12);
      var2.a("Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)\u0000".getBytes("UTF-16LE"));
      var3[0] = 16;
      Arrays.fill(var3, 1, 4, (byte)0);
      var2.a(var3, 0, 4);
      var2.a(this.e);
      byte[] var4 = new byte[32];
      byte[] var5 = new byte[]{0, 17, 17, 34, 34, 50, 51, 67, 68, 84, 85, 69, 36, 60, 68, 4};
      System.arraycopy(this.a(var5), 0, var4, 0, 20);
      this.b.doFinal(var5, 0, var5.length, var5);
      var2.a(var5);
      var3[0] = 20;
      Arrays.fill(var3, 1, 4, (byte)0);
      var2.a(var3, 0, 4);
      this.b.doFinal(var4, 0, 16, var4);
      this.b.doFinal(var4, 16, 16, var4, 16);
      var2.a(var4);
      var2.a().a(0L, 0);
      return var1;
   }

   public com.aspose.cells.b.a.d.zh b(com.aspose.cells.b.a.d.zh var1) throws Exception {
      com.aspose.cells.b.a.d.za var2 = new com.aspose.cells.b.a.d.za(var1);
      byte[] var3 = new byte[8];
      zaks.a(var3, 0, var1.h());
      int var4 = ((int)var1.h() + 15) / 16;
      com.aspose.cells.b.a.d.zh var5 = new com.aspose.cells.b.a.d.zh(var4 * 16 + 8);
      com.aspose.cells.b.a.d.zb var6 = new com.aspose.cells.b.a.d.zb(var5);
      var6.a(var3);
      var3 = new byte[16];

      int var7;
      for(var7 = 0; var7 < var4 - 1; ++var7) {
         var2.a(var3, 0, 16);
         this.b.doFinal(var3, 0, var3.length, var3);
         var6.a(var3);
      }

      var7 = var2.a(var3, 0, 16);
      if (var7 > 0) {
         if (var7 < 16) {
            Arrays.fill(var3, var7, 16, (byte)0);
         }

         this.b.doFinal(var3, 0, 16, var3);
         var6.a(var3);
      }

      var5.a(0L, 0);
      return var5;
   }

   private short a(int var1) {
      switch(var1) {
      case 128:
         return 26126;
      case 192:
         return 26127;
      case 256:
         return 26128;
      default:
         throw new IllegalArgumentException("Unsupported key size: " + var1);
      }
   }

   private int b(int var1) {
      switch(var1) {
      case 26126:
         return 128;
      case 26127:
         return 192;
      case 26128:
         return 256;
      default:
         throw new IllegalArgumentException("Unsupported keyAlgId: " + var1);
      }
   }

   private byte[] a(byte[] var1) {
      this.a.update(var1);
      return this.a.digest();
   }
}
